#include "gpio.h"
#include "LPC17xx.h"
#include "led.h"
#include "uart.h"
#include "pin_config.h"

/* LED pin definitions */
led_t leds[4] = {{BANK_1, PIN_18},{BANK_1, PIN_20},{BANK_1, PIN_21},{BANK_1, PIN_23}};

/**
 * LED initialization
 *
 * @param  none
 * @return none
 *
 * @brief  initialize pins for led use
 *
 *
 */
void led_init(void)
{
    uint8_t i;

    /* initialize gpios */
    for (i = 0; i < sizeof(leds); i++)
    {
        gpio_configure(leds[i].port, leds[i].pin, PIN_OUTPUT);
    }
}

/**
 * Set LED
 *
 * @param  led_t *led
 * @return none
 *
 * @brief  switch on LED
 *
 *
 */
uint32_t led_set(led_t *led)
{
    return gpio_set(led->port, led->pin, ON);
}

/**
 * Clear LED
 *
 * @param  led_t *led
 * @return none
 *
 * @brief  switch off LED
 *
 *
 */
uint32_t led_clear(led_t *led)
{
    return gpio_set(led->port, led->pin, OFF);
}

/**
 * Switch LED
 *
 * @param  led_t *led
 * @return none
 *
 * @brief  toggle LED state
 *
 *
 */
void led_switch(led_t *led)
{
    if (gpio_get(led->port, led->pin))
    {
        gpio_set(led->port, led->pin, OFF);
    }
    else
    {
        gpio_set(led->port, led->pin, ON);
    }
    return;
}


